<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/cookie.js"></script>
</head>

<body>
    <button class="set">创建</button>
    <button class="get">获取</button>
    <button class="edit">修改</button>
    <button class="delete">删除</button>
</body>
<script>
    var set = document.getElementsByClassName("set")[0];
    var get = document.getElementsByClassName("get")[0];
    var edit = document.getElementsByClassName("edit")[0];
    var del = document.getElementsByClassName("delete")[0];

    // 如何删除cookie?
    // 1. 手动删除   => 调试cookie
    // 2. 将过期时间设置为已经去过的时间   => 1. 键值赋值为"" 2. 刷新页面
    //   一般情况下,如果不设置过期时间,cookie在浏览器关闭就过期
    //             如果设置过期时间,超过指定时间就会过期  => 关闭浏览器/刷新页面 过期cookie会被清除


    set.onclick = function () {
        setCookie("user", "a123123", 31);
        setCookie("pwd", "123123", 31);
        setCookie("phone", "17386141517", 31);
        setCookie("email", "123123@qq.com", 31);
    }

    get.onclick = function () {
        console.log(getCookie("user"));
        console.log(getCookie("pwd"));
        console.log(getCookie("phone"));
        console.log(getCookie("email"));
        console.log(getCookie("heihei"));
    }

    edit.onclick = function(){
        setCookie("user", "b123123", 7);
        setCookie("pwd", "123321", 7);
        setCookie("phone", "1738666666", 7);
        setCookie("email", "99999@qq.com", 7);
    }

    del.onclick = function(){
        setCookie("user", "", -1);
        setCookie("pwd", "", -1);
        setCookie("phone", "", -1);
        setCookie("email", "", -1);

        // window.close();
        location.reload();
    }

    
</script>

</html>